"""
写入文件
"""
import csv

import requests

url = "http://129.211.129.101:9006/user/login.do"
file1 = open("../data/logintest.csv", 'r', encoding='utf-8')
file2 = open("../data/testres.csv", "w")
table = csv.reader(file1)
userinfo = {}
i = 0
for row in table:
    if i == 0:
        pass
    else:
        userinfo['username'] = row[0]
        userinfo['password'] = row[1]
        userinfo['res'] = row[2]
        res = requests.post(url, data=userinfo).text
        r = res.find(row[2])
        if r > 0:
            print("接口测试通过")
            file2.write(f"{row[0]},{row[1]},{row[2]},测试通过\n")
        else:
            print("接口测试失败")
            file2.write(f"{row[0]},{row[1]},{row[2]},测试失败\n")

    i = i + 1
file2.close()
